package com.github.cyf.controller;

import com.github.cyf.common.module.Rs;
import com.github.cyf.service.TestService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author chenyifan
 * @create 2024-09-02 17:28
 */
@RestController
@RequestMapping ("/test")
@Slf4j
@RequiredArgsConstructor
@ApiSupport(order = 1)
@Api(tags = "测试接口")
public class TestController {

    private final TestService testService;

    @GetMapping("/sync")
    @ApiOperation("单线程测试")
    @ApiOperationSupport(order = 1)
    public Rs test1(){
        log.info("sync test in controller");
        testService.test1();
        return Rs.ok("执行成功");
    }

    @GetMapping("/subThread")
    @ApiOperation("子线程测试")
    @ApiOperationSupport(order = 2)
    public Rs test2() {
        log.info("subThread test in controller");
        testService.test2();
        return Rs.ok("执行成功");
    }

    @GetMapping("/async")
    @ApiOperation("异步测试，使用默认线程池")
    @ApiOperationSupport(order = 3)
    public Rs test3() {
        log.info("async test in controller");
        testService.test3();
        return Rs.ok("执行成功");
    }

    @GetMapping("/asyncByCustomPool")
    @ApiOperation("异步测试，使用自定义异步MDC线程池代码")
    @ApiOperationSupport(order = 4)
    public Rs test4() {
        log.info("async test in controller");
        testService.test4();
        return Rs.ok("执行成功");
    }

    @GetMapping("/asyncByCustomTask")
    @ApiOperation("异步测试，使用自定义MDC任务")
    @ApiOperationSupport(order = 5)
    public Rs test5() {
        log.info("async test in controller");
        testService.test5();
        return Rs.ok("执行成功");
    }
}
